[id].vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <TopicHead></TopicHead>
  5. <!-- 商圈详情 -->
  6. <div class="topicInfoBox">
  7. <div class="inner">
  8. <!-- 详情头部 -->
  9. <div class="infoHead">
  10. <div class="left">
  11. <div class="userInfo left">
  12. <el-badge value="楼主" class="item" type="warning">
  13. <img v-if='dataInfo.avatar' :src="dataInfo.avatar" alt="">
  14. <img v-else src='../../public/topic/Rectangle.png' alt="">
  15. </el-badge>
  16. <span>{{ dataInfo.nickname }}</span>
  17. </div>
  18. <div class="headContent left">
  19. <h2>{{ dataInfo.title }}</h2>
  20. <p v-show="dataInfo.group_name">
  21. 群聊:
  22. <span>{{ dataInfo.group_name }}</span>
  23. <button @click="joinGroup">加入群聊</button>
  24. </p>
  25. </div>
  26. </div>
  27. <div class="right">
  28. <div class="one" v-if="dataInfo.type == 1">科研</div>
  29. <div class="two" v-else-if="dataInfo.type == 2">维权</div>
  30. <div class="three" v-else-if="dataInfo.type == 3">讨论</div>
  31. <p>{{ dataInfo.updated_at }}</p>
  32. </div>
  33. </div>
  34. <!-- 详情页 文本+图片 -->
  35. <div class="infoContent" v-show="dataInfo.content">
  36. <div v-html="dataInfo.content"></div>
  37. </div>
  38. <div class="infoContent1" v-show="!dataInfo.content">
  39. <img src="../../public/topic/Document_empty.png" alt="">
  40. <span>可以看看大家的互动哦~</span>
  41. </div>
  42. <!-- 详情页评论 -->
  43. <div class="comment">
  44. <h3>评论</h3>
  45. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  46. <div class="left">
  47. <img v-if='item.avatar' :src="item.avatar" alt="" >
  48. <img v-else src='../../public/topic/Rectangle.png' alt="">
  49. <span class="name">{{ item.nickname }} : </span>
  50. <span class="context">{{ item.content }}</span>
  51. </div>
  52. <div class="right">
  53. <span class="time">{{ item.created_at }}</span>
  54. <!-- <span>回复</span> -->
  55. </div>
  56. </div>
  57. <div class="comment_empty" v-show="page_total == 0">
  58. <img src="../../public/topic/message_empty.png" alt="">
  59. <span>暂无评论</span>
  60. </div>
  61. </div>
  62. <!-- 分页 -->
  63. <div class="paginationBox" v-show="page_total != 0">
  64. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  65. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  66. </div>
  67. </div>
  68. </div>
  69. <div class="message">
  70. <div class="inner">
  71. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  72. <button class="btn" @click="addReply">确定</button>
  73. </div>
  74. </div>
  75. <!-- 页面底部 -->
  76. <!-- <HomeFoot></HomeFoot> -->
  77. <AdvertisingFoot></AdvertisingFoot>
  78. </div>
  79. </template>
  80. <script setup>
  81. //1.引用模块 start ---------------------------------------->
  82. //使用ref和reactive动态变量
  83. import { ref, reactive, onMounted } from 'vue'
  84. import { useRoute } from 'vue-router';
  85. //使用官方ssr请求模块
  86. import { useNuxtApp, useFetch } from '#app'
  87. //使用element-plus组件
  88. import { ElPagination, ElBadge, ElInput, ElMessage, ElMessageBox } from 'element-plus';
  89. // axios请求
  90. const nuxtApp = useNuxtApp();
  91. const axios = nuxtApp.$axios;
  92. //1.引用模块 end ---------------------------------------->
  93. // 定义响应式数据
  94. const seoData = ref({
  95. title: '商圈',
  96. description: '默认描述',
  97. keywords: '默认关键词',
  98. image: 'https://example.com/default-image.jpg'
  99. });
  100. // 在 onMounted 钩子中获取数据
  101. onMounted(()=>{
  102. seoData.value.title = '商圈';
  103. seoData.value.description = '默认描述';
  104. seoData.value.keywords = '默认关键词';
  105. })
  106. //2.页面数据 start ---------------------------------------->
  107. const dataInfo = ref({})
  108. const groupId = useState("groupId", () => '')
  109. const replyList = useState("replyList", () => []) //评论列表
  110. //分页
  111. const page = ref(1)
  112. const pageSize = ref(5)
  113. let page_total = ref(0)
  114. const content = ref('')
  115. //2.页面数据 end ---------------------------------------->
  116. //3.获取商圈详情 start ---------------------------------------->
  117. const route = useRoute();
  118. const id = route.params.id; // 获取传递的 id 参数
  119. //页码发生改变
  120. const changePage = (val) => {
  121. console.log(val);
  122. page.value = val
  123. getTopicReply()
  124. }
  125. // 商圈信息
  126. const getTopicInfo = () => {
  127. let data = new FormData()
  128. data.append('id', id)
  129. axios.post('chat/getTopicInfo', data).then(res => {
  130. console.log('商圈信息', res);
  131. dataInfo.value = res.data
  132. groupId.value = res.data.group_id
  133. console.log(groupId.value);
  134. })
  135. }
  136. // 回复商圈 列表
  137. const getTopicReply = () => {
  138. let data = new FormData()
  139. data.append('id', id)
  140. data.append('page', page.value)
  141. data.append('page_size', pageSize.value)
  142. axios.post('chat/getTopicReply', data).then(res => {
  143. console.log('回复商圈列表 ', res);
  144. replyList.value = res.data.data
  145. // page_total.value = res.data.total
  146. page_total.value = res.data.total
  147. console.log("replyList", replyList);
  148. })
  149. }
  150. onMounted(() => {
  151. getTopicInfo(); //商圈信息
  152. getTopicReply(); //回复商圈列表
  153. })
  154. //加入群聊
  155. const joinGroup = () => {
  156. ElMessageBox.confirm(
  157. '加入群聊后,页面跳转至后台群聊页面',
  158. '是否加入群聊?',
  159. {
  160. confirmButtonText: '是',
  161. cancelButtonText: '否',
  162. center: true,
  163. }
  164. ).then(() => {
  165. console.log('groupId.value', groupId.value);
  166. let data = new FormData()
  167. data.append('group_id', groupId.value)
  168. axios.post('chat/joinGroup', data).then(res => {
  169. console.log('加入群聊 ', res);
  170. if (res.code == 0 && res.message !== '已加入群') {
  171. ElMessage.error(res.message)
  172. } else if (res.code == 0 && res.message == '已加入群') {
  173. ElMessage({
  174. message: res.message,
  175. type: 'success',
  176. })
  177. setTimeout(() => {
  178. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  179. }, 1000)
  180. } else if (res.code == 200) {
  181. ElMessage({
  182. message: '加入成功',
  183. type: 'success',
  184. })
  185. setTimeout(() => {
  186. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  187. }, 1000)
  188. }
  189. })
  190. }).catch(() => {
  191. ElMessage({
  192. type: 'error',
  193. message: '已取消',
  194. })
  195. })
  196. }
  197. // 回复商圈
  198. const addReply = () => {
  199. let data = new FormData()
  200. data.append('id', id)
  201. data.append('content', content.value)
  202. axios.post('chat/addReply', data).then(res => {
  203. console.log('回复商圈 ', res);
  204. if (res.code == 0) {
  205. ElMessage.error(res.message)
  206. getTopicReply();
  207. } else if (res.code == 200) {
  208. ElMessage({
  209. message: '回复成功',
  210. type: 'success',
  211. })
  212. content.value = ''
  213. getTopicReply();
  214. }
  215. })
  216. }
  217. //3.获取商圈详情 end ---------------------------------------->
  218. </script>
  219. <style lang="less" scoped>
  220. .topicInfoBox {
  221. .inner {
  222. width: 1200px;
  223. margin: 0 auto;
  224. //信息头部
  225. .infoHead {
  226. height: 200px;
  227. padding: 65px 0 60px 40px;
  228. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  229. box-sizing: border-box;
  230. >.left {
  231. .userInfo {
  232. margin-right: 90px;
  233. .item {
  234. margin-top: -5px;
  235. margin-right: -5px;
  236. :deep(.el-badge__content.is-fixed) {
  237. position: absolute;
  238. right: calc(1px + var(--el-badge-size) / 2);
  239. top: 0;
  240. transform: translateY(-31%) translateX(79%);
  241. z-index: var(--el-index-normal);
  242. }
  243. img {
  244. width: 66px;
  245. height: 66px;
  246. vertical-align: middle;
  247. border-radius: 50%;
  248. }
  249. }
  250. span {
  251. margin-left: 15px;
  252. font-family: Microsoft YaHei, Microsoft YaHei;
  253. font-weight: 400;
  254. font-size: 18px;
  255. color: #333333;
  256. }
  257. }
  258. .headContent {
  259. h2 {
  260. width: 750px;
  261. height: 56px;
  262. line-height: 28px;
  263. display: -webkit-box;
  264. -webkit-box-orient: vertical;
  265. -webkit-line-clamp: 2;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. word-break: break-all;
  269. font-family: Microsoft YaHei, Microsoft YaHei;
  270. font-weight: bold;
  271. font-size: 20px;
  272. color: #333333;
  273. margin-bottom: 26px;
  274. }
  275. >p {
  276. font-family: Microsoft YaHei, Microsoft YaHei;
  277. font-weight: 400;
  278. font-size: 16px;
  279. color: #333333;
  280. button {
  281. width: 86px;
  282. height: 32px;
  283. background-color: #028e21;
  284. color: #fff;
  285. border: none;
  286. margin-left: 100px;
  287. }
  288. }
  289. }
  290. }
  291. >.right {
  292. position: relative;
  293. div {
  294. position: absolute;
  295. right: 0;
  296. top: 0;
  297. width: 71px;
  298. height: 32px;
  299. line-height: 32px;
  300. text-align: center;
  301. background-color: #d9f0d6;
  302. margin-bottom: 29px;
  303. font-family: Microsoft YaHei, Microsoft YaHei;
  304. font-weight: 400;
  305. font-size: 16px;
  306. color: #33B023;
  307. }
  308. .one {
  309. color: #FFAA33;
  310. background-color: #fbebd5;
  311. }
  312. .two {
  313. color: #33B023;
  314. background-color: #d5ecd2;
  315. }
  316. .three {
  317. color: #666;
  318. background-color: #ebebeb;
  319. }
  320. p {
  321. width: 150px;
  322. text-align: right;
  323. position: absolute;
  324. top: 62px;
  325. right: 0;
  326. }
  327. }
  328. }
  329. // 有详情信息
  330. .infoContent {
  331. width:1196px;
  332. overflow: hidden;
  333. padding: 40px 46px;
  334. font-family: Microsoft YaHei, Microsoft YaHei;
  335. font-size: 20px;
  336. line-height: 40px;
  337. box-sizing: border-box;
  338. div{
  339. word-wrap: break-word; /* 强制长单词或 URL 换行 */
  340. overflow-wrap: break-word; /* 现代推荐用法,等同于 word-wrap */
  341. white-space: pre-wrap; /* 保留空白字符并允许自动换行 */
  342. word-break: break-all; /* 强制在任意字符处换行 */
  343. }
  344. }
  345. .leftBottom::v-deep p{
  346. width:1200px;
  347. white-space: pre-wrap;
  348. }
  349. //没有详情信息
  350. .comment_empty,
  351. .infoContent1 {
  352. height: 300px;
  353. line-height: 260px;
  354. text-align: center;
  355. img {
  356. width: 78px;
  357. height: 78px;
  358. vertical-align: -25px;
  359. vertical-align: middle;
  360. margin-right: 20px;
  361. }
  362. span {
  363. font-family: Microsoft YaHei, Microsoft YaHei;
  364. font-weight: bold;
  365. font-size: 26px;
  366. color: #CCCCCC;
  367. }
  368. }
  369. //评论
  370. .comment {
  371. h3 {
  372. height: 100px;
  373. padding-top: 30px;
  374. box-sizing: border-box;
  375. border-bottom: 1px solid #E1E1E1;
  376. font-family: Microsoft YaHei, Microsoft YaHei;
  377. font-weight: 400;
  378. font-size: 22px;
  379. color: #000000;
  380. }
  381. .commentList {
  382. height: 112px;
  383. border: 1px solid #E1E1E1;
  384. background-color: #fafafa;
  385. margin-top: 20px;
  386. padding: 30px 30px;
  387. box-sizing: border-box;
  388. .left {
  389. width:920px;
  390. // overflow: hidden;
  391. img {
  392. float: left;
  393. width: 52px;
  394. height: 52px;
  395. border-radius: 50%;
  396. vertical-align: middle;
  397. margin-right: 15px;
  398. }
  399. span{
  400. float: left;
  401. height: 52px;
  402. line-height: 22px;
  403. padding-top: 10px;
  404. }
  405. .name {
  406. font-family: Microsoft YaHei, Microsoft YaHei;
  407. font-weight: 400;
  408. font-size: 16px;
  409. color: #333333;
  410. margin-right: 30px;
  411. }
  412. .context {
  413. width:760px;
  414. display: -webkit-box;
  415. -webkit-box-orient: vertical;
  416. -webkit-line-clamp: 2;
  417. overflow: hidden;
  418. text-overflow: ellipsis;
  419. word-break: break-all;
  420. font-family: Microsoft YaHei, Microsoft YaHei;
  421. font-weight: bold;
  422. font-size: 16px;
  423. color: #333333;
  424. }
  425. }
  426. .right {
  427. padding: 14px 0;
  428. .time {
  429. font-family: Microsoft YaHei, Microsoft YaHei;
  430. font-weight: 400;
  431. font-size: 16px;
  432. color: #999999;
  433. margin-right: 30px;
  434. }
  435. span {
  436. font-family: Microsoft YaHei, Microsoft YaHei;
  437. font-weight: 400;
  438. font-size: 16px;
  439. color: #333333;
  440. }
  441. }
  442. }
  443. // .comment_empty {
  444. // height: 200px;
  445. // line-height: 200px;
  446. // text-align: center;
  447. // img {
  448. // width: 78px;
  449. // height: 78px;
  450. // vertical-align: -25px;
  451. // margin-right: 20px;
  452. // }
  453. // span {
  454. // font-family: Microsoft YaHei, Microsoft YaHei;
  455. // font-weight: bold;
  456. // font-size: 26px;
  457. // color: #CCCCCC;
  458. // }
  459. // }
  460. }
  461. }
  462. }
  463. //评论回复
  464. .message {
  465. width: 100%;
  466. height: 145px;
  467. line-height: 145px;
  468. background-color: #ecf5ee;
  469. .inner {
  470. .messageInput {
  471. width: 1049px;
  472. height: 67px;
  473. outline: none;
  474. border: 1px solid #E1E1E1;
  475. background-color: #fafafa;
  476. font-family: Microsoft YaHei, Microsoft YaHei;
  477. font-weight: 400;
  478. font-size: 18px;
  479. color: #666;
  480. padding: 0 20px;
  481. box-sizing: border-box;
  482. }
  483. .btn {
  484. width: 115px;
  485. height: 40px;
  486. border: none;
  487. background-color: #028e21;
  488. color: #fff;
  489. border-radius: 6px;
  490. margin-left: 36px;
  491. font-family: Microsoft YaHei, Microsoft YaHei;
  492. font-weight: 400;
  493. font-size: 16px;
  494. }
  495. }
  496. }
  497. //分页
  498. .paginationBox {
  499. display: flex;
  500. justify-content: center;
  501. margin-top: 60px;
  502. margin-bottom: 90px;
  503. // 鼠标移入后字体颜色
  504. :deep(.el-pagination:hover) {
  505. color: #139609;
  506. }
  507. :deep(.el-pagination.is-background .btn-next),
  508. :deep(.el-pagination.is-background .btn-prev) {
  509. width: 70px;
  510. height: 34px;
  511. margin: 0px 10px;
  512. border-radius: 4px;
  513. }
  514. :deep(.el-pagination.is-background .el-pager li) {
  515. margin: 0px 10px;
  516. width: 38px;
  517. height: 34px;
  518. border-radius: 4px;
  519. }
  520. :deep(.el-pagination.is-background .btn-next.is-active),
  521. :deep(.el-pagination.is-background .btn-prev.is-active),
  522. :deep(.el-pagination.is-background .el-pager li.is-active) {
  523. background-color: #028e21;
  524. color: #fff;
  525. }
  526. }
  527. </style>